package com.letfox.test.example;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.common.util.UUIDHexGenerator;
import com.letfox.finance.dao.AccountRlInoutDao;
import com.letfox.finance.enums.FINDelEnums;
import com.letfox.finance.enums.FINInoutTypeEnums;
import com.letfox.finance.model.FINAccountRlInout;
import com.letfox.test.util.DateUtil;
import com.letfox.test.util.MyBatisUtil;

public class AccountRlInoutExample {

	private AccountRlInoutDao accountRlInoutDao;
	
	@Test
	public void add(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		FINAccountRlInout finAccountRlInout = new FINAccountRlInout();
		finAccountRlInout.setId(100L);
		finAccountRlInout.setFinAccountId("40289a81628943470162894347380000");
		finAccountRlInout.setFinInoutId(UUIDHexGenerator.generator());
		finAccountRlInout.setFinInoutType(FINInoutTypeEnums.FININOUTTYPE.INCOME.getValue());		
		finAccountRlInout.setCreateTime(new Date());
		finAccountRlInout.setUpdateTime(new Date());
		finAccountRlInout.setCreateBy("admin");
		finAccountRlInout.setUpdateBy("admin");
		finAccountRlInout.setDel(FINDelEnums.UDMDel.EFFECTIVE.getValue());
		accountRlInoutDao = session.getMapper(AccountRlInoutDao.class);
		accountRlInoutDao.insertSelective(finAccountRlInout);
	}
	
	@Test
	public void update(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		FINAccountRlInout finAccountRlInout = new FINAccountRlInout();
		finAccountRlInout.setDel(FINDelEnums.UDMDel.DELETE.getValue());
		accountRlInoutDao = session.getMapper(AccountRlInoutDao.class);
		accountRlInoutDao.updateByPrimaryKeySelective(finAccountRlInout);
	}
	
	@Test
	public void select(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		accountRlInoutDao = session.getMapper(AccountRlInoutDao.class);
		FINAccountRlInout finAccountRlInout = accountRlInoutDao.selectByPrimaryKey(100L);
		System.out.println(finAccountRlInout.toString());
	}

	@Test
	public void select_date(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		accountRlInoutDao = session.getMapper(AccountRlInoutDao.class);
		Map map = new HashedMap();
		
		
		map.put("finAccountId", "1");
		map.put("startTime", DateUtil.strToDateSql("2018-03-15 00:00:00"));
		map.put("endTime", DateUtil.strToDateSql("2018-03-19 18:00:00"));
		
		
		
		List<FINAccountRlInout> finAccountRlInouts = accountRlInoutDao.periodTime_incomeDetail(map);
		System.out.println(finAccountRlInouts.size());
	}
}
